/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package commons.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Utilities regarding date and time not found in the external libraries currently being used.
 *
 * @author Susanta Tewari
 * @version 1.1.0
 * @history Created on Nov 10, 2011
 * @since 1.1.0
 */
public class DateTimeUtil {

    /**
     * Makes this class un-instantiable. This is a class with static methods only.
     */
    private DateTimeUtil() {}

    /**
     * A string representation of current date and time in the format {@code yyyy-MM-dd_hh-mm-ss}.
     *
     * @return current date and time in the format {@code yyyy-MM-dd_hh-mm-ss}
     * @deprecated use {@link #getCurrentDateTime()} instead, has a better method name but the same
     *             implementation
     */
    public static String getDateTime() {

        DateFormat df = new SimpleDateFormat("yyyy-MM-dd_hh-mm-ss");

        return df.format(new Date());
    }


    /**
     * A string representation of current date and time in the format {@code yyyy-MM-dd_hh-mm-ss}.
     *
     * @return current date and time in the format {@code yyyy-MM-dd_hh-mm-ss}
     */
    public static String getCurrentDateTime() {

        DateFormat df = new SimpleDateFormat("yyyy-MM-dd_hh-mm-ss");

        return df.format(new Date());
    }


    /**
     * Gets the first day of the current month.
     *
     * @return the first day of the current month
     */
    public static Date getFirstDayOfMonth() {

        Calendar calendar = Calendar.getInstance();

        calendar.setTime(new Date());
        calendar.set(Calendar.DAY_OF_MONTH, 1);

        return calendar.getTime();
    }
}
